home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2005 October
/
PCWOCT05.iso
/
Software
/
FromTheMag
/
Syn Text Editor 2.1.0.46
/
synsetup-2.1.0.46.exe
/
{app}
/
templates
/
Pascal
/
OpenGL.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2003-08-13
|
4KB
|
155 lines
{Description: OpenGL Program|}
{
Created: {$DateTime} by {$UserName}
$Id: OpenGL.pas,v 1.1.2.3 2003/08/13 00:38:45 neum Exp $
}
{ Translated from the OpenGL Template from Dev-C++ }
{ This file compiles with FreePascal 1.0.6 and Delphi 5, and maybe some others }
program {$FileTitleNoExt};
{$APPTYPE GUI}
uses
Windows,
SysUtils,
{$ifdef FPC}
OpenGL32,
gl
{$else}
Messages,
OpenGL
{$endif}
;
const
AppTitle = '{$FileTitleNoExt}';
ClassName = '{$FileTitleNoExt}WindowClass';
var
Msg: TMsg;
Handle: HWND; { Handle of the Mainwindow }
bQuit: boolean;
gHDC: HDC;
procedure DisableOpenGL(hWnd: HWND; hDC: HDC; hRC: HGLRC);
begin
wglMakeCurrent(0, 0);
wglDeleteContext(hRC);
ReleaseDC(hWnd, hDC);
end;
procedure EnableOpenGL(hWnd: HWND; var hDC: HDC; var hRC: HGLRC);
var
pfd: PIXELFORMATDESCRIPTOR;
iFormat: integer;
begin
{ get the device context (DC) }
hDC := GetDC(hWnd);
{ set the pixel format for the DC }
FillChar(pfd, SizeOf(pfd), 0);
pfd.nSize := SizeOf(pfd);
pfd.nVersion := 1;
pfd.dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
pfd.iPixelType := PFD_TYPE_RGBA;
pfd.cColorBits := 24;
pfd.cDepthBits := 16;
pfd.iLayerType := PFD_MAIN_PLANE;
{$ifdef FPC}
iFormat := ChoosePixelFormat(hDC, pfd);
{$else}
iFormat := ChoosePixelFormat(hDC, @pfd);
{$endif}
SetPixelFormat(hDC, iFormat, @pfd);
{ create and enable the render context (RC) }
hRC := wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
end;
function WndProc(HWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
{ Window procedure, add here your message handlers }
case Msg of
WM_DESTROY:
begin
bQuit := true;
PostQuitMessage(0);
WndProc := 0;
end;
else
WndProc := DefWindowProc(HWnd, Msg, WParam, LParam);
end;
end;
procedure ProcessMessages;
var
theta: double;
begin
{ Wait for Messages }
theta := 0.0;
while not bQuit do begin
if PeekMessage(Msg, Handle, 0, 0, PM_REMOVE) then begin
if Msg.message = WM_QUIT then
bQuit := true
else begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end else begin
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix;
glRotatef(theta, 0.0, 0.0, 1.0);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0); glVertex2f(0.0, 1.0);
glColor3f(0.0, 1.0, 0.0); glVertex2f(0.87, -0.5);
glColor3f(0.0, 0.0, 1.0); glVertex2f(-0.87, -0.5);
glEnd;
glPopMatrix;
SwapBuffers(gHDC);
theta := theta + 1.0;
Sleep(1);
end;
end;
end;
var
{ Global Variables }
WClass: TWndClass;
gHRC: HGLRC;
begin
with WClass do begin
Style := CS_HREDRAW or CS_VREDRAW;
lpfnWndProc := @WndProc;
cbClsExtra := 0;
cbWndExtra := 0;
hInstance := HInstance;
hIcon := LoadIcon(0, IDI_APPLICATION);
hCursor := LoadCursor(0, IDC_ARROW);
hbrBackground := COLOR_WINDOW + 1;
lpszMenuName := PChar(AppTitle);
lpszClassName := PChar(ClassName);
end;
RegisterClass(WClass);
Handle := CreateWindow(PChar(ClassName), PChar(AppTitle), WS_OVERLAPPEDWINDOW, 0,
0, 200, 200, 0, 0, HInstance, nil);
if Handle = 0 then begin
MessageBox(0, 'Unable to create Window.', PChar(AppTitle), MB_ICONSTOP + MB_OK);
end else begin
EnableOpenGL(Handle, gHDC, gHRC);
bQuit := false;
ShowWindow(Handle, SW_SHOW);
ProcessMessages;
DisableOpenGL(Handle, gHDC, gHRC);
DestroyWindow(Handle);
end;
end.